package com.whpu.mall.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * 跨域问题统一处理
 */
@Configuration
public class MallCorsConfiguration {


    @Bean
    public CorsWebFilter corsWebFilter(){

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration cors = new CorsConfiguration();  //处理跨域

        //配置跨域
        cors.addAllowedHeader("*"); //任意请求头
        cors.addAllowedMethod("*"); //任意请求方式
        cors.addAllowedOrigin("*"); //任意请求来源
        cors.setAllowCredentials(true);   //是否允许携带cookie

        source.registerCorsConfiguration("/**",cors);

        return new CorsWebFilter(source);
    }
}
